import axios from 'axios'
import { useUserStore } from '@/stores/user'

// 获取当前用户ID
function getCurrentUserId() {
  const userStore = useUserStore()
  return userStore.userInfo?.id
}

export function postMessage(message) {
  const userId = getCurrentUserId()
  return axios.get('/api/ai/chat', {
    params: { message, userId }
  })
}

export function getChatStream(message) {
  const userId = getCurrentUserId()
  const params = new URLSearchParams({
    message: message,
    userId: userId
  });
  const url = `/api/ai/chat?${params.toString()}`;
  return new EventSource(url);
} 